
//
//  NSAttributedString+Externsion.swift
//  ZMWeiboSwift
//
//  Created by pg on 2017/8/3.
//  Copyright © 2017年 pg. All rights reserved.
//

import UIKit

extension NSAttributedString {
    
    //根据表情模型创建表情富文本
    class func attributedStringWith(emotionModel:ZMEmotionModel , font: UIFont)->NSAttributedString{
        //创建图片对象
        let image = UIImage(named:emotionModel.path! , in: ZMEmotiontools.sharedTools.emotionBundle, compatibleWith:nil)
        //创建文本附件
        let textAttachment = ZMTextAttachment()
        
        
        //关联文本附件和对应的表情模型
        textAttachment.emotionModel = emotionModel
        //设置文本附件所需要的图片
        textAttachment.image = image
        //获取文字行高
        let lineHeight = font.lineHeight
        //设置富文本的bounds
        textAttachment.bounds = CGRect(x:0,y:-4,width:lineHeight,height: lineHeight)
        //根据文本附件创建富创建富文本
        let attrbutedStr = NSAttributedString(attachment:textAttachment)
        
        return attrbutedStr
        
        
    }
    
}



